package cn.siques.backend.controller;

import cn.siques.backend.dto.model.Result;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.parser.Feature;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.core.io.ClassPathResource;
import org.springframework.security.core.parameters.P;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Paths;

/**
 * @author : heshenghao
 * @date : 14:52 2021/1/1
 */
@RestController
@RequestMapping("/emoji")
public class EmojiController {

    @GetMapping()
    @Cacheable(cacheNames="emoji")
    public Result emoji() throws IOException {
        ClassPathResource resource = new ClassPathResource("emoji.json");
        URI uri = resource.getURI();
        byte[] bytes = Files.readAllBytes(Paths.get(uri));
        Object parse = JSON.parse(bytes, Feature.AllowArbitraryCommas);
        return Result.succeed(parse);
    }
}
